import axios from 'axios'
import axiosFetch from '../../fetch/axios'

const state = {}

const mutations = {}

const actions = {
    registUser({ commit }, params) {
        return new Promise((resolve, reject) => {
            axiosFetch.fetchPost('/user/register', params).then(responseData => {
                return resolve(responseData);
            }, err => {
                return reject(err)
            });
        })
    },
    login({ commit }, params) {
        return new Promise((resolve, reject) => {
            axiosFetch.fetchPost('/user/login', params).then(responseData => {
                return resolve(responseData);
            }, err => {
                return reject(err)
            });
        })
    },
    update({ commit }, params) {
        return new Promise((resolve, reject) => {
            axiosFetch.fetchPost('/user/updateintegral', params).then(responseData => {
                return resolve(responseData);
            }, err => {
                return reject(err)
            });
        })
    },
    checkUserInfo({ commit }, openid) {
        return new Promise((resolve, reject) => {
            axios.get('/user/check', {　
                params: { 'openid': openid }
            }).then(function(response) {　
                return resolve(response.data);
            }).catch(function(error) {　　
                return reject(error)　
            });
        })
    }
}


const getters = {}

export default {
    state,
    mutations,
    actions,
    getters
}